/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.gui;

import java.util.List;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import model.dao.DaoAluno;
import model.dominio.Aluno;
import model.dominio.Turma;
import model.dominio.Falta;
/**
 *
 * @author Teao
 */
public class GuiTurmaConsultar extends javax.swing.JPanel {
    
    private List<Aluno> listaAluno;

    public GuiTurmaConsultar() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        SelBusca = new javax.swing.ButtonGroup();
        jDialog1 = new javax.swing.JDialog();
        jDialog2 = new javax.swing.JDialog();
        txtNomeBusca = new javax.swing.JTextField();
        buscarAdm = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabAluno = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtNomeBusca1 = new javax.swing.JTextField();
        txtNomeBusca2 = new javax.swing.JTextField();
        salvar = new javax.swing.JButton();
        removerTurma = new javax.swing.JButton();
        removerDados = new javax.swing.JButton();

        setLayout(null);
        add(txtNomeBusca);
        txtNomeBusca.setBounds(290, 60, 40, 40);

        buscarAdm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/gui/icones/buscar.png"))); // NOI18N
        buscarAdm.setText("BUSCAR");
        buscarAdm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarAdmActionPerformed(evt);
            }
        });
        add(buscarAdm);
        buscarAdm.setBounds(510, 40, 120, 40);

        tabAluno.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Nota", "Falta", "Aprovação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabAluno.setToolTipText("");
        jScrollPane1.setViewportView(tabAluno);

        add(jScrollPane1);
        jScrollPane1.setBounds(20, 130, 620, 250);

        jLabel2.setText("Disciplina: ");
        add(jLabel2);
        jLabel2.setBounds(30, 20, 60, 20);

        jLabel3.setText("Ano:");
        add(jLabel3);
        jLabel3.setBounds(60, 70, 50, 20);

        jLabel4.setText("Período:");
        add(jLabel4);
        jLabel4.setBounds(240, 70, 50, 14);
        add(txtNomeBusca1);
        txtNomeBusca1.setBounds(120, 10, 370, 40);
        add(txtNomeBusca2);
        txtNomeBusca2.setBounds(120, 60, 40, 40);

        salvar.setText("Salvar Faltas");
        salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarActionPerformed(evt);
            }
        });
        add(salvar);
        salvar.setBounds(470, 400, 170, 40);

        removerTurma.setText("Remover Turma");
        add(removerTurma);
        removerTurma.setBounds(20, 400, 120, 40);

        removerDados.setText("Remover Dados");
        add(removerDados);
        removerDados.setBounds(150, 400, 150, 40);
    }// </editor-fold>//GEN-END:initComponents

    private void buscarAdmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarAdmActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_buscarAdmActionPerformed

    private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed
        
        Falta falta;
        falta.getAluno()
        DaoAluno atDao = new DaoAluno();
        int i = 0;
        for (Aluno al : listaAluno) {
            try{
                int valor;
                valor = (Integer) tabAluno.getValueAt(i, 3);
                
                al.setFaltas(valor);
                
                atDao.update(alT);
                i+=1;
            }catch(Exception e){
                
            }
        }
            Aluno aluno = new Aluno();
            for (int i = 2; i <=3; i++) {
                if (tabAluno.isEditing()) {
                    tabAluno.
                }
                    
            
            aluno.setNome(nome.getText());
            aluno.setCpf(cpf.getText());
            DaoAluno dao = new DaoAluno();
            aluno = (Aluno) dao.salvar(aluno);
            if (aluno != null) {
                JOptionPane.showMessageDialog(this, "Dados registrados com sucesso", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
                this.setVisible(false);
            }      
    }//GEN-LAST:event_salvarActionPerformed
/**/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup SelBusca;
    private javax.swing.JButton buscarAdm;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JDialog jDialog2;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton removerDados;
    private javax.swing.JButton removerTurma;
    private javax.swing.JButton salvar;
    private javax.swing.JTable tabAluno;
    private javax.swing.JTextField txtNomeBusca;
    private javax.swing.JTextField txtNomeBusca1;
    private javax.swing.JTextField txtNomeBusca2;
    // End of variables declaration//GEN-END:variables

    private void atualizarTabela() {
        DefaultTableModel model = (DefaultTableModel) tabAluno.getModel();
        Object[] linha = new Object[3];

        model.setRowCount(0);
        
        Turma t =(Turma) comboTurma.getSelectedItem();
        listaAT = t.getAlunoTurmas();
        for (AlunoTurma at : listaAT) {
             
             linha[0] = at.getAluno().getNome();
             linha[1] = at.getAluno().getCpf();
             linha[2] = at.getFaltas();
            
             model.addRow(linha);
        }
        tabela.repaint();
    }
    
}
